﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace NeonMika.EightTracks
{
    public static class ExpansionMethods
    {
        public static string TryGetStringElement(this XElement xml, string element)
        {
            if ( xml.Element(element) != null && xml.Element(element).Attribute("nil") == null )
                return xml.Element(element).Value.ToString( );
            else
                return null;
        }

        public static int TryGetIntElement(this XElement xml, string element)
        {
            int outint = 0;
            if ( xml.Element(element) != null && xml.Element(element).Attribute("nil") == null )
                if ( Int32.TryParse(xml.Element(element).Value.ToString( ), out outint) )
                    return outint;
                else return -1;
            else return -1;
        }

        public static bool TryGetBoolElement(this XElement xml, string element)
        {
            if ( xml.Element(element) != null && xml.Element(element).Attribute("nil") == null )
                return xml.Element(element).Value.ToString( ) == "true" ? true : false;
            else
                return false;
        }
    }
}
